# 列表推导式 [expression for item in list]
# 先运行for循环，然后在执行表达式

# 最简形式
# list_val = []
# for i in range(1,6):
#     list_val.append(i**2)
# print(list_val)
#
# list_val1 = [i**2 for i in range(1,6)]
# print(list_val1)
#
# word_list = ['I','love','python']
# print([i.upper() for i in word_list])
# print([i.capitalize() for i in word_list])

# 过滤条件形式 [expression for item in list if condition]
# print([i for i in range(21) if i%2 == 0])
# names = ['zhangshan','wangwu','xiahoudun']
# new_names = []
# for i in names:
#     if len(i) < 8:
#         new_names.append(i.lower())
#     else:
#         new_names.append(i.upper())
# print(new_names)

# if-else 形式 使用三目运算符
# print([i.lower() if len(i) < 8 else i.upper() for i in names])

# 循环嵌套形式 [expression for i in list1 for j in list2]
data_1 = '高富帅'
data_2 = '白富美'
list_val = []
for i in data_1:
    for j in data_2:
        list_val.append(i+j)
print(list_val)

print([ i+j for i in data_1 for j in data_2])